using System.Net;
using System.IO;

public class HttpResponseEx
{
	private HttpWebResponse _response;
	private Stream _stream;
	public HttpResponseEx(HttpRequestEx request)
	{
		_response = (HttpWebResponse)request.request.GetResponse();
	}

	public void GetStream()
	{
		_stream = _response.GetResponseStream();
	}

	public long ContentLength
	{
		get
		{
			return _response.ContentLength;
		}
	}

	public WebHeaderCollection Headers
	{
		get
		{
			return _response.Headers;
		}
	}

	public int ReadTimeout
	{
		set
		{
			_stream.ReadTimeout = value;
		}
	}

	public int Read(byte[] buf, int offset, int len)
	{
		return _stream.Read(buf, offset, len);
	}

	public void Close()
	{
		if(_stream != null)
		{
			_stream.Close();
			_stream = null;
		}

		if(_response != null)
		{
			_response.Close();
			_response = null;
		}
	}
}

public class HttpRequestEx
{
	private HttpWebRequest _request;

	public static HttpRequestEx Create(string url)
	{
		HttpRequestEx r = new HttpRequestEx();
		r.create(url);
		return r;
	}

	public HttpWebRequest request
	{
		get
		{
			return _request;
		}
	}

	private HttpRequestEx()
	{

	}

	private void create(string url)
	{
		_request = (HttpWebRequest)WebRequest.Create(url);
	}

	public string Method
	{
		set
		{
			_request.Method = value;
		}
	}

	public int ConnectionLimit
	{
		set
		{
			_request.ServicePoint.ConnectionLimit = value;
		}
	}

	public int Timeout
	{
		set
		{
			_request.Timeout = value;
		}
	}

	public int ReadWriteTimeout
	{
		set
		{
			_request.ReadWriteTimeout = value;
		}
	}

	public void AddRange(int from, int to)
	{
		_request.AddRange(from, to);
	}

	public HttpResponseEx GetResponse()
	{
		HttpResponseEx response = new HttpResponseEx(this);
		return response;
	}

	public void Abort()
	{
		_request.Abort();
	}
}
